package com.ruoyi.exam.controller;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.exam.domain.entity.exentity.ExamStatic;
import com.ruoyi.exam.domain.entity.exentity.TaskScoreQueryDTO;
import com.ruoyi.exam.domain.entity.exentity.TaskScoreResultDTO;
import com.ruoyi.exam.domain.entity.exentity.UserExamScore;
import com.ruoyi.exam.service.IStaticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.math.BigDecimal;
import java.util.List;

@RestController
@RequestMapping("/exam/statics")
public class StaticsController extends BaseController {
    @Autowired
    private IStaticsService staticsService;

    
    /**
     * 获取部门用户考试分数统计
     */
    @GetMapping(value = "/userScores")
    public TableDataInfo  getUserExamScores(@RequestParam(value = "deptId", required = false) Long deptId){
        List<UserExamScore> list=staticsService.getUserExamScore(deptId);
        return  getDataTable(list);

    }
    /***
     * 获取统计信息
     */
    @GetMapping(value = "/statistics")
    public TableDataInfo list(@RequestParam(value = "deptId", required = false) Long deptId)
    {
        List<ExamStatic> list=staticsService.getExamStatistics(deptId);
        return  getDataTable(list);
    }
    @GetMapping("/task-score")
    public TableDataInfo getLowScoreTasks(TaskScoreQueryDTO queryDTO) {
        startPage(); // 开启分页
        List<TaskScoreResultDTO> list = staticsService.getLowScoreTaskList(queryDTO);
        return getDataTable(list); // 封装成若依格式返回
    }
    @GetMapping("/task-score/export")
    public void exportLowScoreTasks(TaskScoreQueryDTO queryDTO, HttpServletResponse response) {
        // 注意：不要加分页 startPage()
        queryDTO.setPageNum(null);
        queryDTO.setPageSize(null);
        List<TaskScoreResultDTO> list = staticsService.getLowScoreTaskList(queryDTO);
        ExcelUtil<TaskScoreResultDTO> util = new ExcelUtil<>(TaskScoreResultDTO.class);
        util.exportExcel(response, list, "考试记录");

    }

} 